<?php
	include("../design/header.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<script language="javascript" src="../scripts/rule.js"></script>
<script language="javascript" src="../scripts/user.js"></script>

<script>
	function submitUpdate(form1,update){
		
		if(document.getElementById('text_password').value!=''){
			submitNow(form1,update);				
		}
		else{
			alert('Please Enter The New Password!');
			document.getElementById('text_password').focus();
		}
		
	}
</script>

<link rel="stylesheet" type="text/css" href="../design/main.css" />
<title>User Management</title>
<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
</head>
<body>

<?php
$row_count = 1;
$temp_count=0;
$user_id = 0;

$operation =  $_GET["operation"];

if($operation!=NULL){ // update Operation
	$row_count = 0;
	$user_id = $_GET["user_id"];
		
	require_once("../../business/UserController.php");	
	
	$userObj = new UserController();
	$result = $userObj->getUsersData($user_id);

	while ($row = mysql_fetch_array($result)){
		
		if($temp_count==0){
			$user_name = $row[0];
			$password = $row[2];
		}

		$page_id[$temp_count] = $row[1];
		$temp_count++;	
		$row_count++;	
	}
	
			
}

require_once("../../business/RetrieveComboData.php");
$comboObj = new RetrieveComboData();


//print_r($col);
?>

<table id="mainTable" width="100%" class="mainTableHeight1024x768" border="0" cellpadding="0" cellspacing="0">
<tr>
    <td width="50" valign="top" class="LeftBgColor">&nbsp;<?php include("../design/leftMenu.php"); ?>
	</td>
    <td valign="top">


<table id="table1" name="table1" align="center" cellpadding="0" cellspacing="0" border="0" >
<form id="form1" name="form1" method="post" action="../../controller/ControlManagement.php?param=userPost">


	    <tr>
    	<td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
    </tr>
        <tr>
    	<td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
    </tr>
<?php
$param =  $_GET["insert"];
if($param!=NULL){
	if($param=="true") {
?>
    <tr>
    	<td colspan="8" class="Labels">Data Successfully Inserted</td>
    </tr>

<?php
	
    }
	else if($param=="false") {
?>
    <tr>
    	<td colspan="8" class="Labels"><span class="style1">Data could not be inserted !!</span></td>
    </tr>

<?php
	
    }
}
?>

  <tr>
    	<td colspan="8" class="TableHeader">Create Users</td>
     
    </tr>
   
    <tr>
        <td ><input type="hidden" id="criteria_counter" name="criteria_counter" value='<?php echo $row_count; ?>'></td>
        <td ><input type="hidden" id="user_id" name="user_id" value='<?php echo $user_id;?>'></td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
    </tr>
   
   <tr>
       <td class="Labels"><u>Create User:</u></td>
   </tr>
   
   <tr>
       <td colspan="8">&nbsp;</td>
   </tr>
    <tr>
    	<td class="Labels">User Login:</td>
        <td><input name="text_user_name" id="text_user_name" type="text"  class="InputText" size="16" value='<?php echo $user_name;?>' /></td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
    </tr>
	   <tr>
       <td colspan="8">&nbsp;</td>
   </tr>
    <tr>
	    <td class="Labels">Password:</td>
		<td><input name="text_password" id="text_password" type="password"  class="InputText" size="16" value='' /></td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>

    </tr>    
    
    <tr>
    	<td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
    </tr>

   <tr>
       <td class="Labels" ><u>Roles:</u></td>
   </tr>
   
   <tr>
    	<td colspan="8">&nbsp;</td>
   </tr> 
   
   	<?php
	
    	for($i=0;$i<$row_count;$i++){
	
	?>		
	
    <tr id='role<?php echo $i; ?>'>
    
    	<td class="Labels">Page Access</td>
        <td>
        <select name="combo_page[]" id='combo_page<?php echo $i;?>' class="InputComboList">
          <?php 
		  	if(operation!=NULL) {  

				 echo $comboObj->getData("select page_id, description from ota_page where page_id!=page_parent_id",$page_id[$i]);
			 }else {

				 echo $comboObj->getData("select page_id, description from ota_page where page_id!=page_parent_id",0);
			 } 

		  ?>
        </select>
       </td>
 
   	    <td><input type="button" name="btn_addRolesRow" id="btn_addRolesRow" value="Add" onClick="addRolesRow('table1');" class="InputButton"></td>
        <?php
        	if($i>0){
				?>
                
                <td>
                <input type="button" name='role<?php echo $i;?>_btn' id='role<?php echo $i;?>_btn' value="Remove" onClick="removeCriteriaRow('table1',this);" class="InputButton">
                </td>
				<?php
			}
		?>
        <td ></td>
	      <td colspan="4">&nbsp;</td>
    </tr>
	<?php
    	}// end of for
	
	?>
    <tr>
    	<td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
    </tr>
    
    <tr>    	
        <td  colspan="8" align="center">
        	<?php
            	if($operation!=NULL){
				
				?>
        	<input name="btn_submit"  type="button"  size="40" class="InputButton" value="Update" onClick="submitUpdate('form1','update');"/>        
                <?php
				} else {
			?>
        <input name="btn_submit" type="button" size="40" class="InputButton" value="Submit" onClick="submitNow('form1','insert');"/>
        	<?php
            	}
			?>
        </td>
    </tr>
  </form>  
</table>
    </td>
 </tr>   
</table>


</body>
</html>